package com.exchange.controller.app.market;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.exchange.common.model.MarketConfig;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class MarketService {
	
	
	/**
     * 交易对配置
     */
    public Ret pairs(){
    	List<MarketConfig> coinTeam = MarketConfig.dao.findByCache("coinTeams", "coinTeams", "SELECT * FROM t_market_config WHERE state = 1 ");
    	Map<String, MarketConfig> coinTeamMap = coinTeam.stream().collect(Collectors.toMap(MarketConfig::getCoinTeam, Function.identity() ));
    	return Ret.ok("coinTeamMap", coinTeamMap);
    }
    
    /**
     * 市场配置
     */
    public Ret market() {
    	List<Record> marketNameList = Db.findByCache("markets", "markets", "SELECT DISTINCT market from t_market_config WHERE state = 1 ");
    	return Ret.ok("marketNameList", marketNameList);
    }
}
